package cn.tedu.coolshark.controller;

import cn.tedu.coolshark.entity.Hot;
import cn.tedu.coolshark.mapper.HotMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.List;

@RestController
public class hotController {
    @Autowired
    HotMapper mapper;
    //把配置文件中的值读取出
    @Value("${dirPath}")
    private String dirPath;
    @RequestMapping("/hot/select")
    public List<Hot> select(){
        return mapper.select();
    }
    @RequestMapping("/hot/delete")
    public void delete(int id){
        String url = mapper.selectUrlById(id);
        new File(dirPath+url).delete();
        mapper.deleteById(id);
    }
}
